from src.Card import EventCardStack
import Base
MAXROOMATE = 6
POS_STARTER = 1

class RoomPosition(object):
    UserInfo = None
    lnext = None
    lahead = None
    Pos = None
    def __init__(self,starter = 0):
        self.Token = 0
        self.Begin = starter
    
    def sit(self,userinfo):
        self.UserInfo = userinfo
    
    def ishead(self):
        return self.Begin

class RoomPositionManager(object):
    size = 6
    def __init__(self,head=None):
        self.roomhead = RoomPosition(POS_STARTER)
        self.roomhead.Pos = 0
        self.posTag = self.roomhead
        tmp = self.roomhead
        for i in range(0,self.size-1):
            tmp.lnext = RoomPosition()
            NewRoom = tmp.lnext
            NewRoom.Pos = i+1
            NewRoom.lahead = tmp
            if i == self.size - 2:
                NewRoom.lnext = self.roomhead
    
    def SitUsr(self,usr):
        i = 0
        while self.posTag.UserInfo != None:
            self.posTag = self.posTag.lnext
            i = i+1
            if i == self.size:
                break
        if(i == self.size):
            raise Base.GameRoomPosFullException()
        else:
            self.posTag.sit(usr)


class Room(object):
    def __init__(self):
        self.GameEnv = GameEnv()
        self.Game = Game()
        self.users = []
        #init the RoomPosition
        self.rpm = RoomPositionManager()
            
    def AddUsr(self,ConnectionInfo):
        if len(self.users) < MAXROOMATE:
            self.users.append(ConnectionInfo)
            self.rpm.SitUsr(ConnectionInfo)
        else:
            raise Base.GameRoomFullException()
        

class GameEnv:
    def __init__(self,Users):
        pass
    
    

class Game:
    def __init__(self,ConnectResource):
        self.mEventCardSet = EventCardStack()
        